import request from '@/config/axios'
import type { Dayjs } from 'dayjs'

/** 每日食谱信息 */
export interface RecipeMenusDaily {
  id: number // 编号 mealId
  menuId?: number // 周食谱ID
  menuDate?: string | Dayjs // 哪一天
  weekDay: string // 周几
  mealType: string // 餐别
  recipeId: number // 菜谱ID
  status?: number // 状态
}

// 每日食谱 API
export const RecipeMenusDailyApi = {
  // 查询每日食谱分页
  getRecipeMenusDailyPage: async (params: any) => {
    return await request.get({ url: `/school/recipe-menus-daily/page`, params })
  },

  // 查询一周食谱的食材用量
  getRecipeMenusDailyUsage: async (menuId: number) => {
    return await request.get({ url: `/school/recipe-menus-daily/recipe-usage?menuId=${menuId}` })
  },

  // 查询一周食谱采购清单
  getRecipeMenusDailyShopping: async (menuId: number) => {
    return await request.get({
      url: `/school/recipe-menus-daily/recipe-shopping-list?menuId=${menuId}`
    })
  },

  // 查询一天食谱采购清单
  getRecipeMenusDailyShoppingDay: async (params: any) => {
    return await request.get({ url: `/school/recipe-menus-daily/recipe-shopping-day`, params })
  },

  // 查询一周食谱的食材营养含量
  getRecipeMenusDailyNutrient: async (menuId: number) => {
    return await request.get({ url: `/school/recipe-menus-daily/recipe-nutrient?menuId=${menuId}` })
  },

  // 查询每周营养分析报告
  getDailyNutritionReport: async (menuId: number) => {
    return await request.get({
      url: `/school/recipe-menus-daily/daily-nutrition-report?menuId=${menuId}`
    })
  },

  // 食物过敏统计
  getRecipeFoodAllergyReport: async (menuId: number) => {
    return await request.get({
      url: `/school/recipe-menus-daily/allergy_report?menuId=${menuId}`
    })
  },

  // 查询每日食谱详情
  getRecipeMenusDaily: async (id: number) => {
    return await request.get({ url: `/school/recipe-menus-daily/get?id=` + id })
  },

  // 新增每日食谱
  createRecipeMenusDaily: async (data: RecipeMenusDaily) => {
    return await request.post({ url: `/school/recipe-menus-daily/create`, data })
  },

  // 修改每日食谱
  updateRecipeMenusDaily: async (data: RecipeMenusDaily) => {
    return await request.put({ url: `/school/recipe-menus-daily/update`, data })
  },

  // 删除每日食谱
  deleteRecipeMenusDaily: async (mealId: number) => {
    return await request.delete({ url: `/school/recipe-menus-daily/delete?id=` + mealId })
  },

  /** 批量删除每日食谱 */
  deleteRecipeMenusDailyList: async (ids: number[]) => {
    return await request.delete({
      url: `/school/recipe-menus-daily/delete-list?ids=${ids.join(',')}`
    })
  },

  // 导出每日食谱 Excel
  exportRecipeMenusDaily: async (params) => {
    return await request.download({ url: `/school/recipe-menus-daily/export-excel`, params })
  }
}
